package com.common.bean;

import io.swagger.annotations.ApiModel;
import lombok.Data;

public class Response<T> {

    private Integer code;

    private String msg;

    private T respData;

    private static int SERVE_RERROR=500;

    public Response(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.respData = data;
    }

    public Response() {
    }

    public Response(T data) {
        this.respData = data;
    }

    public static<T> Response<T> ok(T data){
        Response<T> response = new Response<T>(data);
        response.setCode(0);
        response.setMsg("success");
        return response;
    }
    public static<T> Response<T> success(){
        Response<T> Response = new Response<T>(null);
        Response.setCode(0);
        Response.setMsg("success");
        return Response;
    }
    public static<T> Response<T> fail(String msg){
        Response<T> response = new Response<T>();
        response.setCode(SERVE_RERROR);
        response.setMsg(msg);
        return response;
    }
    public static<T> Response<T> fail(Integer code, String msg){
        Response<T> response = new Response<T>();
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }
    public Response<T> msg(String msg){
        this.setMsg(msg);
        return this;
    }

    public Response<T> code(Integer code){
        this.setCode(code);
        return this;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getRespData() {
        return respData;
    }

    public void setRespData(T respData) {
        this.respData = respData;
    }

    public static int getServeRerror() {
        return SERVE_RERROR;
    }

    public static void setServeRerror(int serveRerror) {
        SERVE_RERROR = serveRerror;
    }
}
